/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-10-27
 * Time: 14:59
 *
 */
class Solution2 {
    public String countAndSay(int n) {
        String ret = "1";
        //n为1的时候，直接返回"1"，题目中明确
        for(int i = 1; i < n; i++){
            //用于存储我们解释中的修改操作
            StringBuilder tmp = new StringBuilder();
            int len = ret.length();
            for(int left = 0, right = 0; right < len;){
                while(right < len && ret.charAt(left) == ret.charAt(right)){
                    right++;
                }
                tmp.append(Integer.toString(right - left));
                tmp.append(ret.charAt(left));
                left = right;
            }
            ret = tmp.toString();
        }
        return ret;
    }
    public static void main(String[] args) {
        String ret = new Solution2().countAndSay(4);
    }
}

public class Test2 {

}
